﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrowserGameFramework.Common.Configuration;

namespace BrowserGameFramework.Mail
{
    public class MailServerConfig
    {

        public string Host { get; set; }
        public int Port { get; set; }
        public string User { get; set; }
        public string Pass { get; set; }
        public bool UseSSL { get; set; }
        public string ReplyMail { get; set; }

        public MailServerConfig()
        {

        }

        /// <summary>
        /// Checks the corectness of the configuration
        /// </summary>
        /// <returns>[True] ready for work [false] failed!</returns>
        public bool IsCorrect()
        {
            if (string.IsNullOrEmpty(this.Host))
            {
                return false;
            }

            if (this.Port == 0)
            {
                return false;
            }

            if (string.IsNullOrEmpty(this.User))
            {
                return false;
            }

            if (string.IsNullOrEmpty(this.Pass))
            {
                return false;
            }

            if (string.IsNullOrEmpty(this.ReplyMail))
            {
                return false;
            }

            return true;

        }

        /// <summary>
        /// Gets the configuration from the application config file
        /// </summary>
        /// <returns></returns>
        public static MailServerConfig GetAppConf()
        {
            MailServerConfig config = new MailServerConfig();

            config.Host = AppConfMan.GetKeyAsString("SmtpHost");
            config.Port = AppConfMan.GetKeyAsInt("SmtpPort");
            config.User = AppConfMan.GetKeyAsString("SmtpUser");
            config.Pass = AppConfMan.GetKeyAsString("SmtpPass");
            config.UseSSL = AppConfMan.GetKeyAsBool("UseSSL");

            return config;
        }
    }
}
